package cn.jekun.web.shop.bean;

import java.util.List;

import javax.servlet.http.HttpSessionBindingEvent;

import cn.jekun.component.base.bean.SessionUser;
import cn.jekun.component.base.spring.SpringUtils;
import cn.jekun.component.core.Constants;
import cn.jekun.component.core.bean.gen.RsAuth;
import cn.jekun.component.core.service.LogService;

/**
 * 登录的用户，保存在session中
 * 
 * @author yuan
 * 
 */
public class WebUser extends SessionUser {

	private String userName; // 用户名
	private String shopId; // 当前商家代码(默认)
	private String shopName; // 当前商家名称(默认)
	private String shopMobile; //当前商家手机号码
	private int shopSize; // 商家数量(分店)
	private String mobile;// 手机号
	private String realName; //商家真实姓名
	private UserLogin loginlogs; //商家登录
	private String shopLogoUrl;//商家图标

	public String getShopLogoUrl() {
		return shopLogoUrl;
	}

	public void setShopLogoUrl(String shopLogoUrl) {
		this.shopLogoUrl = shopLogoUrl;
	}

	public String getShopMobile() {
		return shopMobile;
	}

	public void setShopMobile(String shopMobile) {
		this.shopMobile = shopMobile;
	}

	public String getAgentMobile() {
		return agentMobile;
	}

	public void setAgentMobile(String agentMobile) {
		this.agentMobile = agentMobile;
	}

	private String logintype; //用户类型
    private String agentId; //当前代理商代码
    private String agentName; //当前代理商名称
	private String agentMobile;//当前代理商手机号码
	
	public String getAgentName() {
		return agentName;
	}

	public void setAgentName(String agentName) {
		this.agentName = agentName;
	}

	public String getAgentId() {
		return agentId;
	}

	public void setAgentId(String agentId) {
		this.agentId = agentId;
	}

	public String getLogintype() {
		return logintype;
	}

	public void setLogintype(String logintype) {
		this.logintype = logintype;
	}

	public UserLogin getLoginlogs() {
		return loginlogs;
	}

	public void setLoginlogs(UserLogin loginlogs) {
		this.loginlogs = loginlogs;
	}

	public String getRealName() {
		return realName;
	}

	public void setRealName(String realName) {
		this.realName = realName;
	}

	private List<UserShops> userShops; // 商家(分店列表)
	private List<RsAuth> menus;//菜单
	public int getShopSize() {
		return shopSize;
	}

	public void setShopSize(int shopSize) {
		this.shopSize = shopSize;
	}

	public WebUser() {
		this.setSystemId(Constants.RS_SYSTEM.SHOP);// 商家后台
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getShopId() {
		return shopId;
	}

	public void setShopId(String shopId) {
		this.shopId = shopId;
	}

	public String getShopName() {
		return shopName;
	}

	public void setShopName(String shopName) {
		this.shopName = shopName;
	}

	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	public List<UserShops> getUserShops() {
		return userShops;
	}

	public void setUserShops(List<UserShops> userShops) {
		this.userShops = userShops;
	}
	public List<RsAuth> getMenus() {
		return menus;
	}

	public void setMenus(List<RsAuth> menus) {
		this.menus = menus;
	}
	
	@Override
	protected void afterLogin(HttpSessionBindingEvent event) {
		super.afterLogin(event);
		//记录登录日志
		try{
			LogService logService = SpringUtils.getBean(LogService.BEAN_NAME);
			if("2".equals(this.logintype)){
			  logService.addShopLoginLog(this.getUserId(), this.getBrowser(), this.getIp(),"商家后台用户登录系统");
			}
//			if("3".equals(this.logintype)){
//			  logService.addAgentLoginLog(this.getUserId(), this.getBrowser(), this.getIp(),"代理商后台用户登录系统");
//			}
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	@Override
	protected void afterLogout(HttpSessionBindingEvent event) {
		super.afterLogout(event);
		//记录退出日志
		try{
			if(this.getUserId()!=null){
				LogService logService = SpringUtils.getBean(LogService.BEAN_NAME);
				if("2".equals(this.logintype)){
				  logService.addShopLogoutLog(this.getUserId(), this.getBrowser(), this.getIp(),"商家后台用户退出系统");
				}
//				if("3".equals(this.logintype)){
//				  logService.addAgentLogoutLog(this.getUserId(), this.getBrowser(), this.getIp(),"代理商后台用户退出系统");
//				}
			}
		}catch(Exception e){
			e.printStackTrace();
		}
	}

}
